package br.perfiman.service.impl.patterns.strategy.brokerage;

import br.perfiman.model.Broker;
import br.perfiman.model.Trade;

/**
 * Abstract class that will be used to calculate do brokerage's value basing
 *  on broker's rules
 * 
 * @author Wagner Costa
 * @since 28/04/2008
 * @version 1.0
 *
 */
public abstract class BrokerageStrategy {

	/**
	 * Calculates the Brokerage's value according with the strategy defined at runtime
	 * 
	 * @author Wagner Costa
	 * @since 28/04/2008
	 * @version 1.0
	 * @param trade
	 * @return
	 */
	public abstract Double getBrokerage(Trade trade);
	
	/**
	 * Returns the better strategy basing on the broker's rules
	 * 
	 * @author Wagner Costa
	 * @since 28/04/2008
	 * @version 1.0
	 * @param broker
	 * @return
	 */
	public static BrokerageStrategy getStrategy(Broker broker){
		BrokerageStrategy toReturn = null;
		switch (broker.getPayType()) {
			case Broker.PAY_TYPE_STATIC:
					toReturn = new BrokerageStaticStrategy();
				break;
			case Broker.PAY_TYPE_RANGE:
				toReturn = new BrokerageRangeStrategy();
			break;
		}
		return toReturn;
	}
}
